// components/PasswordForm.tsx
import { useState } from 'react';
import { useAuth } from '../context/AuthContext';

export const PasswordForm = () => {
  const [password, setPassword] = useState('');
  const [error, setError] = useState('');
  const { login } = useAuth();

  const handleSubmit = async (e: React.FormEvent) => {
    e.preventDefault();
    setError('');
    try {
      await login(password);
    } catch {
      setError('Invalid password');
    }
  };

  return (
    <form onSubmit={handleSubmit} className="password-form">
      <input
        type="password"
        value={password}
        onChange={(e) => setPassword(e.target.value)}
        placeholder="Enter password"
        required
      />
      <button type="submit">Login</button>
      {error && <p className="error">{error}</p>}
    </form>
  );
};